package com.antifly.common.config;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * MybatisPlus插件配置
 *
 * @author LuoJiaHui
 * @date 2023/1/10 10:58
 * @description
 */
@Configuration
@MapperScan("com.*.*.*.mapper")
@ComponentScan(basePackages = {"com.antifly.common.dao.impl"})
public class MybatisConfig {

    /**
     * Mybatis-Plus查询下划线转驼峰
     *
     * @return com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer
     * @author LuoJiaHui
     * @date 2023/1/10 10:58
     **/
    @Bean
    public ConfigurationCustomizer mybatisConfigurationCustomizer() {
        return configuration -> configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
    }

    /**
     * 配置分页插件
     *
     * @return com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
     * @author LuoJiaHui
     * @date 2023/4/25 10:38
     **/
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 不声明数据库类型自行判断
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return interceptor;
    }
}
